package bite;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * Creared with IntelliJ IDEA.
 * Description:淘宝网店】NowCoder在淘宝上开了一家网店。他发现在月份为素数的时候，当月每天能赚1元；否则每天能赚2元。
 * 现在给你一段时间区间，请你帮他计算总收益有多少。
 * User:yxd
 * Date:2022-06-08
 * Time:16:21
 */
public class Day32_1 {
    //另外也可以先单独计算每一年的收益,然后计算该年开始从给出的日子的收益,开始的话减去这个收益就是剩下的收益,而结束就是这个收益,另外需要注意其实年和结束年是不是同一年
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        while(input.hasNextLine()){
            String s = input.nextLine();
            String[] arr = s.split(" ");
            int year1 = Integer.parseInt(arr[0]);
            int year2 = Integer.parseInt(arr[3]);
            int month1 = Integer.parseInt(arr[1]);
            int month2 = Integer.parseInt(arr[4]);
            int day1 = Integer.parseInt(arr[2]);
            int day2 = Integer.parseInt(arr[5]);
            long money = 0;
            Set<Integer> set = new HashSet<>();
            set.add(2);
            set.add(3);
            set.add(5);
            set.add(7);
            set.add(11);
            int[] months = {0,31,28,31,30,31,30,31,31,30,31,30,31};
            for(int i = year1;i <= year2;i ++){
                if((i % 4 == 0 && i % 100 != 0) || (i % 400 == 0)){
                    months[2] = 29;
                }else{
                    months[2] = 28;
                }
                //是在同一年
                if(i == year1 && year1 == year2){
                    for(int j = month1;j <= month2;j ++){
                        //是素数月
                        if(set.contains(j)){
                            //是同一个月
                            if(j == month1 && month1 == month2){
                                for(int z = day1;z <= day2;z ++){
                                    money += 1;
                                }
                                //开始月份
                            }else if(j == month1){
                                for(int z = day1;z <= months[month1];z ++){
                                    money += 1;
                                }
                                //结束月份
                            }else if(j == month2){
                                for(int z = 1;z <= day2;z ++){
                                    money += 1;
                                }
                            }else {
                                //中间月份
                                for (int z = 1;z < months[j];z ++){
                                    money += 1;
                                }
                            }
                        }else {
                            //不是素数月份
                            if(j == month1 && month1 == month2){
                                for(int z = day1;z <= day2;z ++){
                                    money += 2;
                                }
                                //开始月份
                            }else if(j == month1){
                                for(int z = day1;z <= months[month1];z ++){
                                    money += 2;
                                }
                                //结束月份
                            }else if(j == month2){
                                for(int z = 1;z <= day2;z ++){
                                    money += 2;
                                }
                            }else {
                                //中间月份
                                for (int z = 1;z < months[j];z ++){
                                    money += 2;
                                }
                            }
                        }
                    }
                    //不是同一年,但是在开始年
                }else if(i == year1){
                    for(int j = month1;j <= 12;j ++){
                        if(set.contains(j)){
                            //是素数月
                            if(j == month1){
                                for(int z = day1;z <= months[j];z ++){
                                    money += 1;
                                }
                            }else {
                                for(int z = 1;z <= months[j];z ++){
                                    money += 1;
                                }
                            }
                        }else{
                            if(j == month1){
                                for(int z = day1;z <= months[j];z ++){
                                    money += 2;
                                }
                            }else {
                                for(int z = 1;z <= months[j];z ++){
                                    money += 2;
                                }
                            }
                        }
                    }
                }else if(i == year2){
                    for(int j = 1;j <= month2;j ++){
                        if(set.contains(j)){
                            //是素数月
                            if(j == month2){
                                for(int z = 1;z <= day2;z ++){
                                    money += 1;
                                }
                            }else {
                                for(int z = 1;z <= months[j];z ++){
                                    money += 1;
                                }
                            }
                        }else{
                            if(j == month2){
                                for(int z = 1;z <= day2;z ++){
                                    money += 2;
                                }
                            }else {
                                for(int z = 1;z <= months[j];z ++){
                                    money += 2;
                                }
                            }
                        }
                    }
                    //中间年份
                }else{
                    for(int j = 1;j <= 12;j ++){
                        if(set.contains(j)){
                            for(int z = 1;z <= months[j];z ++){
                                money += 1;
                            }
                        }else {
                            for(int z = 1;z <= months[j];z ++){
                                money += 2;
                            }
                        }
                    }
                }
            }
            System.out.println(money);
        }
    }
}
